package com.qianclass.talklive.app.json.ImSendMessge;

import com.qianclass.talklive.app.bean.MicVideoBean;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;
import com.google.gson.Gson;

import static com.qianclass.talklive.app.activity.VideoActivity.egine;


/**
 * 控制命令
 * {
         "message":
         {
             "subcommand":"mic",
             "switch":"off",
             "type":"media",
             "userid":10000004
         }
     }

     {
         "message":
         {
             "subcommand":"camera",
             "switch":"off",
             "type":"media",
             "userid":10000004
         }
     }
 */

public class SendMicVideoMessage {

    /**
     * @param
     * @param userId
     * @param group
     */
    public static void sendMessge(String command, String toggle, int userId, final String group) {
        try {
            MicVideoBean micVideoBean = new MicVideoBean();
            MicVideoBean.MessageBean messageBean = new MicVideoBean.MessageBean();
            messageBean.setSubcommand(command);
            messageBean.setType("media");
            messageBean.setUserid(userId);
            messageBean.setSwitchX(toggle);

            micVideoBean.setMessage(messageBean);

            Gson gson = new Gson();
            final String jsonString = gson.toJson(micVideoBean);
            ThreadUtils.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    egine.SendGroupMessage(Constant.CONTROLMSGTYPE, group, jsonString);
                }
            });
            LogUtil.i("音视频控制命令" ,jsonString);
        } catch (Exception e){
            LogUtil.i("音视频控制命令" , "发送信息失败");
        }

    }
}
